package com.example.test06thread.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @Author: fxy
 * @Date: 2022/05/25/11:11
 * @Description:
 */
public class Test5 {
    public static void main(String[] args) {
        Qq7 qq71 = new Qq7();
        Qq7 qq72 = new Qq7();
        new Thread(()->{
            Qq7.sendMessage();
        },"A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            Qq7.callQq();
        },"B").start();
    }
}
class Qq7{
    /**
     * synchronized锁的对象是方法的调用者
     * static类一加载就执行，所以此时锁的的Qq3的class；一个类的class全局也是唯一的
     */
    public static synchronized void sendMessage(){
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("使用qq发消息");
    }
    //静态同步方法
    public static synchronized void callQq(){
        System.out.println("使用qq打电话");
    }
}
